/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using SES.CMS.DO;
/// <summary>
/// Summary description for cmsOrdersDAL
/// </summary>
namespace SES.CMS.DAL
{

    public class cmsOrdersDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsOrdersDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsOrdersDO objcmsOrdersDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsOrdersDO.CustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreateDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsOrdersDO.CreateDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PaymentId", SqlDbType.Int);
            Sqlparam.Value = objcmsOrdersDO.PaymentId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsEnable", SqlDbType.Bit);
            Sqlparam.Value = objcmsOrdersDO.IsEnable;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Status", SqlDbType.Bit);
            Sqlparam.Value = objcmsOrdersDO.Status;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DateOfStart", SqlDbType.DateTime);
            Sqlparam.Value = objcmsOrdersDO.DateOfStart;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DateOfFisnish", SqlDbType.DateTime);
            Sqlparam.Value = objcmsOrdersDO.DateOfFisnish;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Address", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsOrdersDO.Address;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsOrdersDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Phone", SqlDbType.VarChar);
            Sqlparam.Value = objcmsOrdersDO.Phone;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsView", SqlDbType.Bit);
            Sqlparam.Value = objcmsOrdersDO.IsView;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsOrdersDO objcmsOrdersDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Id", SqlDbType.Int);
            Sqlparam.Value = objcmsOrdersDO.Id;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsOrdersDO.CustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreateDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsOrdersDO.CreateDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PaymentId", SqlDbType.Int);
            Sqlparam.Value = objcmsOrdersDO.PaymentId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsEnable", SqlDbType.Bit);
            Sqlparam.Value = objcmsOrdersDO.IsEnable;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Status", SqlDbType.Bit);
            Sqlparam.Value = objcmsOrdersDO.Status;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DateOfStart", SqlDbType.DateTime);
            Sqlparam.Value = objcmsOrdersDO.DateOfStart;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DateOfFisnish", SqlDbType.DateTime);
            Sqlparam.Value = objcmsOrdersDO.DateOfFisnish;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Address", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsOrdersDO.Address;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsOrdersDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Phone", SqlDbType.VarChar);
            Sqlparam.Value = objcmsOrdersDO.Phone;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsView", SqlDbType.Bit);
            Sqlparam.Value = objcmsOrdersDO.IsView;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsOrdersDO objcmsOrdersDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Id", SqlDbType.Int);
            Sqlparam.Value = objcmsOrdersDO.Id;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsOrdersDO Select(cmsOrdersDO objcmsOrdersDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Id", SqlDbType.Int);
            Sqlparam.Value = objcmsOrdersDO.Id;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["Id"]))
                    objcmsOrdersDO.Id = Convert.ToInt32(dr["Id"]);
                if (!Convert.IsDBNull(dr["CustomerId"]))
                    objcmsOrdersDO.CustomerId = Convert.ToInt32(dr["CustomerId"]);
                if (!Convert.IsDBNull(dr["CreateDate"]))
                    objcmsOrdersDO.CreateDate = Convert.ToDateTime(dr["CreateDate"]);
                if (!Convert.IsDBNull(dr["PaymentId"]))
                    objcmsOrdersDO.PaymentId = Convert.ToInt32(dr["PaymentId"]);
                if (!Convert.IsDBNull(dr["IsEnable"]))
                    objcmsOrdersDO.IsEnable = Convert.ToBoolean(dr["IsEnable"]);
                if (!Convert.IsDBNull(dr["Status"]))
                    objcmsOrdersDO.Status = Convert.ToBoolean(dr["Status"]);
                if (!Convert.IsDBNull(dr["DateOfStart"]))
                    objcmsOrdersDO.DateOfStart = Convert.ToDateTime(dr["DateOfStart"]);
                if (!Convert.IsDBNull(dr["DateOfFisnish"]))
                    objcmsOrdersDO.DateOfFisnish = Convert.ToDateTime(dr["DateOfFisnish"]);
                if (!Convert.IsDBNull(dr["Address"]))
                    objcmsOrdersDO.Address = Convert.ToString(dr["Address"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objcmsOrdersDO.Note = Convert.ToString(dr["Note"]);
                if (!Convert.IsDBNull(dr["Phone"]))
                    objcmsOrdersDO.Phone = Convert.ToString(dr["Phone"]);
                if (!Convert.IsDBNull(dr["IsView"]))
                    objcmsOrdersDO.IsView = Convert.ToBoolean(dr["IsView"]);

            }
            return objcmsOrdersDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsOrdersDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsOrdersDO objcmsOrdersDO = new cmsOrdersDO();
                    if (!Convert.IsDBNull(dr["Id"]))
                        objcmsOrdersDO.Id = Convert.ToInt32(dr["Id"]);
                    if (!Convert.IsDBNull(dr["CustomerId"]))
                        objcmsOrdersDO.CustomerId = Convert.ToInt32(dr["CustomerId"]);
                    if (!Convert.IsDBNull(dr["CreateDate"]))
                        objcmsOrdersDO.CreateDate = Convert.ToDateTime(dr["CreateDate"]);
                    if (!Convert.IsDBNull(dr["PaymentId"]))
                        objcmsOrdersDO.PaymentId = Convert.ToInt32(dr["PaymentId"]);
                    if (!Convert.IsDBNull(dr["IsEnable"]))
                        objcmsOrdersDO.IsEnable = Convert.ToBoolean(dr["IsEnable"]);
                    if (!Convert.IsDBNull(dr["Status"]))
                        objcmsOrdersDO.Status = Convert.ToBoolean(dr["Status"]);
                    if (!Convert.IsDBNull(dr["DateOfStart"]))
                        objcmsOrdersDO.DateOfStart = Convert.ToDateTime(dr["DateOfStart"]);
                    if (!Convert.IsDBNull(dr["DateOfFisnish"]))
                        objcmsOrdersDO.DateOfFisnish = Convert.ToDateTime(dr["DateOfFisnish"]);
                    if (!Convert.IsDBNull(dr["Address"]))
                        objcmsOrdersDO.Address = Convert.ToString(dr["Address"]);
                    if (!Convert.IsDBNull(dr["Note"]))
                        objcmsOrdersDO.Note = Convert.ToString(dr["Note"]);
                    if (!Convert.IsDBNull(dr["Phone"]))
                        objcmsOrdersDO.Phone = Convert.ToString(dr["Phone"]);
                    if (!Convert.IsDBNull(dr["IsView"]))
                        objcmsOrdersDO.IsView = Convert.ToBoolean(dr["IsView"]);
                    arrcmsOrdersDO.Add(objcmsOrdersDO);
                }
            }
            return arrcmsOrdersDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectAll2()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_GetAllOld";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectAllOld(bool Status)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_GetAll1";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Status", SqlDbType.Bit);
            Sqlparam.Value = Status;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable GetByStatus(bool Status)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsOrders_GetByStatus";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Status", SqlDbType.Bit);
            Sqlparam.Value = Status;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        #endregion

    }

}
